define(function(require, exports, module) {
    var ALL = require("../../common/all"),
        CONFIG = ALL.CONFIG,
        METHOD = ALL.METHOD,
        Dialog = ALL.Dialog,
        Init = ALL.Init;

    var _Dialog = new Dialog({
        title : "提示",
        content : "<p></p>",
        text4Btn: ["确定"],
        class4Btn: [""]
    });


    var _vm = Init.initVue({
        data : {
            check: {},
            file : '',
            user_id : '',
            res : {
                type : 1,
                plan_name : '',
                no : '',
                name : '',
                col_id : '',
                cnt : '',
            }
        },
        methods: {
            submit : function() {

                this.check.$valid();
                flag = this.check.flag;

                if (!flag) { return; }

                // new FormData
                var fd = new FormData();
                fd.append("data", JSON.stringify(_vm.res));
                if (_vm.res.type == 2) {
                    fd.append("file", _vm.file);
                }

                METHOD.loading.show();
                METHOD.ajax("lock/plan/add",fd,{type : 'post',upload : true}).done(function(json){
                    METHOD.loading.hide();
                    if (_vm.res.type == 2) {
                        _Dialog.changeCfg({content : "<p>" + json.msg + "</p>"});
                        _Dialog.showUI(function() {
                            _vm.checkAgain();
                            this.hideUI();
                        });
                    } else {
                        _vm.checkAgain();
                    }
                }).fail(function(){
                    METHOD.loading.hide();
                })
            },
            checkAgain : function() {
                METHOD.alert("操作成功").done(function(){
                    window.location.href = "../trade/lock.html";
                });
            },
            uploadFile : function(e, name) {
                var files = e.target.files,
                    file = files[0];

                if (files.length == 0 ) return;

                if (!/^.+\.(xls)|(xlsx)|(csv)$/i.test(file.name)) {
                    METHOD.alert("文件格式有误，请重新导入");
                } else {
                    _vm[name] = file;
                }
            },
            getInfoCallback : function(o) {
                if (o) {
                    this.user_id = o.id;
                    this.res.name = o.name;
                } else {
                    this.user_id = "";
                    this.res.name = "";
                }
            }
        }
    });

});

